package com.glodon.paas.account.web.resource.internal;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.slf4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.glodon.paas.mail.MailMessageParam;
import com.glodon.paas.mail.SpringMailMessage;
import com.glodon.paas.mail.SpringMailSender;
import com.glodon.paas.web.resource.BaseResource;
import com.glodon.paas.web.resource.CommonsResource;

@Component
@Path("/internal")
public class AccountInternalResource extends CommonsResource implements BaseResource{
	@Autowired
    SpringMailSender mailSender;

	@POST
	@Path("/sendMail")
	@Produces(MediaType.APPLICATION_JSON)
	public void sendMail(
			@QueryParam("async") @DefaultValue("true") Boolean async,
			MailMessageParam param
			) {
		
		SpringMailMessage message = new SpringMailMessage();
		BeanUtils.copyProperties(param, message);
		
		if(async == null || async.booleanValue()){
			mailSender.sendAsync(message);
		}else{
			mailSender.send(message);
		}
	}
	
	@Override
	public String getUserId(HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Logger getLoger() {
		// TODO Auto-generated method stub
		return null;
	}

}
